/*
 * event.c
 *
 * event functions
 *
 * Copyright (C) 2020 Long-Horn
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>

#include "event.h"

int event_wrap_data(event_s *event, void *buf, int count)
{
    int res = -1;
    
    if ( NULL != buf && NULL != event) {
        memcpy((void *)event->payload, buf, count > PAYLOAD_LEN_MAX ? PAYLOAD_LEN_MAX : count);
        event->payload_len = count;
        res = 1;
    }
    
    return res;
}

int event_parse_data(event_s *event, void *buf, int count)
{
    int res = -1;
    
    if ( NULL != buf && NULL != event) {
        memcpy(buf, (void *)event->payload, count > event->payload_len ? event->payload_len : count);
        res = 0;
    }
    
    return res;
}

int event_make_response(event_s *event, void *response, int count)
{
    int res = -1;
    
    if ( NULL != response && NULL != event) {
        memcpy(response, (void *)event->payload, count > event->payload_len ? event->payload_len : count);
        res = 0;
    }
    
    return res;
}
